<?php

namespace App\Traits\Relation;

use App\Models\City;
use App\Models\District;
use App\Models\ExpressCompany;
use App\Models\Network;
use App\Models\Province;
use App\Models\Service;
use App\Models\SignOutTally;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\Relation;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;

/**
 * 用于定义网点和其他模型的关系
 *
 * @package App\Traits\Relation
 * Date: 2018/06/11
 * @author Tenny
 */
trait NetworkExpressRelation
{
    /**
     * 获取关联站点数
     *
     * Date: 2018/06/11
     * @author Tenny
     * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
     */
    public function services()
    {
        return $this->HasOne(Service::class, 'id', 'service_id');
    }

    /**
     * 获取关联网点
     *
     * Date: 2018/06/11
     * @author Tenny
     * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
     */
    public function network()
    {
        return $this->HasOne(Network::class, 'id', 'network_id');
    }

    /**
     * 获取关联站点数
     *
     * Date: 2018/06/11
     * @author Tenny
     * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
     */
    public function express()
    {
        return $this->HasOne(ExpressCompany::class, 'id', 'express_id');
    }

    /**
     * 获取关联站点数
     *
     * Date: 2018/06/11
     * @author Tenny
     * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
     */
    public function networkBills()
    {
        return $this->HasMany(SignOutTally::class, 'network_id', 'network_id')->where('sign_out_tally.service_id','network_express.service_id');
    }
}
